(async () => {
  const Koa = require('koa')
  const KoaStaticCache = require('koa-static-cache')
  const KoaBodyParser = require('koa-bodyparser')
  const router = require('./routers/main')
  const session = require('koa-session');

  const app = new Koa()

  // app.use(async (ctx, next) => {
  //   ctx.set('Access-Control-Allow-Origin', '*')
  //   ctx.set('Access-Control-Allow-Credentials', true)
  //   await next()
  // })

  app.use(KoaStaticCache('./public', {
    prefix: '/public',
    gzip: true
  }))

  app.use(KoaBodyParser())

  app.use(router.routes())

  app.keys = ['some secret hurr'];
  const CONFIG = {
    key: 'koa:sess',   //cookie key (default is koa:sess)
    maxAge: 86400000,  // cookie的过期时间 maxAge in ms (default is 1 days)
    overwrite: true,  //是否可以overwrite    (默认default true)
    httpOnly: true, //cookie是否只有服务器端可以访问 httpOnly or not (default true)
    signed: true,   //签名默认true
    rolling: false,  //在每次请求时强行设置cookie，这将重置cookie过期时间（默认：false）
    renew: false,  //(boolean) renew session when session is nearly expired,
  };
  app.use(session(CONFIG, app));

  app.listen(80)

})()